/**
 * Copyright (C) 2012 he110w0r1d <http://he110w0r1d.googlecode.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${groupId};

import java.util.ServiceLoader;

import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.google.guiceberry.GuiceBerryEnvMain;
import com.google.guiceberry.GuiceBerryModule;
import com.google.inject.Module;
import com.google.inject.Provides;

@Log4j
public class AppGuiceBerryEnv extends GuiceBerryModule {

	@Provides
	@SneakyThrows
	HelloService createUserService() {
		Service serviceModel = new ObjectServiceFactory()
				.create(HelloService.class);
		HelloService service = (HelloService) new XFireProxyFactory().create(
				serviceModel, "http://localhost:9999/services/HelloService");
		return service;
	}

	@Override
	protected void configure() {
		super.configure();
		bind(GuiceBerryEnvMain.class).to(JettyServerStarter.class);

		for (Module module : ServiceLoader.load(Module.class)) {
			log.info("loading module: " + module.getClass().getCanonicalName());
			install(module);
		}

	}

}
